package com.slm.report.view.data;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.StringUtils;
import com.slm.report.databinding.ViewRadioContentBinding;

/**
 * @ProjectName: My Application
 * @Package: com.slm.report.view.data
 * @ClassName: RadioContentView
 * @Description: java类作用描述
 * @Author: 王丹丹
 * @CreateDate: 2020/6/1 22:18
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/6/1 22:18
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class RadioContentView extends BaseContentView {
    ViewRadioContentBinding viewRadioContentBinding = null;

    public RadioContentView(Context context) {
        super(context);
        viewRadioContentBinding = ViewRadioContentBinding.inflate(LayoutInflater.from(getContext()), this, true);
        viewRadioContentBinding.rgSex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(viewRadioContentBinding.rgSex.getCheckedRadioButtonId());
                contentDataBean.setContent(radioButton.getText().toString());
                LogUtils.d(contentDataBean.getContent());
            }
        });
    }


    @Override
    void upDataContent() {
        viewRadioContentBinding.titleTv.setText(contentDataBean.getTitleStr());
        if (isEdit) {
            if (StringUtils.isEmpty(contentDataBean.getContent())) {
                contentDataBean.setContent("男");
            }
            viewRadioContentBinding.rgSex.setVisibility(View.VISIBLE);
            viewRadioContentBinding.contentTv.setVisibility(View.GONE);
            if ("女".equals(contentDataBean.getContent())) {
                viewRadioContentBinding.nvRadio.setChecked(true);
            } else {
                viewRadioContentBinding.nanRadio.setChecked(true);
            }
        } else {
            viewRadioContentBinding.rgSex.setVisibility(View.GONE);
            viewRadioContentBinding.contentTv.setVisibility(View.VISIBLE);
            viewRadioContentBinding.contentTv.setText(contentDataBean.getContent());
        }

    }
}
